home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performNormalConstraint.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  14.4 KB  |  551 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  24 April 1997
  22. //
  23. //  Description:
  24. //        This script provides an option box dialog for the normalConstraint command.
  25. //
  26. //    Input Arguments:
  27. //        boolean showOptionBox    true - show the option box dialog
  28. //                                false - just execute the command
  29. //
  30. //  Procedure Name:
  31. //      setOptionVars
  32. //
  33. //  Description:
  34. //        Initialize the option values.
  35. //
  36. //  Input Arguments:
  37. //        Whether to set the options to default values.
  38. //
  39. //  Return Value:
  40. //      None.
  41. //
  42. proc setOptionVars(int $forceFactorySettings)
  43. {
  44.     //    weight
  45.     //
  46.     if ($forceFactorySettings || !`optionVar -exists normalConstraintWeight`) {
  47.         optionVar -floatValue normalConstraintWeight 1.0;
  48.     }
  49.  
  50.     //    aimVector.
  51.     //
  52.     if ($forceFactorySettings || !`optionVar -exists normalConstraintAimVector`) {
  53.         optionVar -floatValue normalConstraintAimVector 1.0
  54.             -floatValueAppend normalConstraintAimVector 0.0
  55.             -floatValueAppend normalConstraintAimVector 0.0;
  56.     }
  57.  
  58.     //    upVector.
  59.     //
  60.     if ($forceFactorySettings || !`optionVar -exists normalConstraintUpVector`) {
  61.         optionVar -floatValue normalConstraintUpVector 0.0
  62.             -floatValueAppend normalConstraintUpVector 1.0
  63.             -floatValueAppend normalConstraintUpVector 0.0;
  64.     }
  65.  
  66.     // World up
  67.  
  68.     if ($forceFactorySettings || !`optionVar -exists normalConstraintWorldUpType`) {
  69.         optionVar -stringValue normalConstraintWorldUpType "vector";
  70.     }
  71.  
  72.     if ($forceFactorySettings || !`optionVar -exists normalConstraintWorldUpVector`) {
  73.         optionVar -floatValue normalConstraintWorldUpVector 0.0
  74.             -floatValueAppend normalConstraintWorldUpVector 1.0
  75.             -floatValueAppend normalConstraintWorldUpVector 0.0;
  76.     }
  77.  
  78.     if ($forceFactorySettings || !`optionVar -exists normalConstraintWorldUpObject`) {
  79.         optionVar -stringValue normalConstraintWorldUpObject "";
  80.     }
  81. }
  82.  
  83. //
  84. //  Procedure Name:
  85. //      normalConstraintSetup
  86. //
  87. //  Description:
  88. //        Update the state of the option box UI to reflect the option values.
  89. //
  90. //  Input Arguments:
  91. //      parent               - Top level parent layout of the option box UI.
  92. //                             Required so that UI object names can be 
  93. //                             successfully resolved.
  94. //
  95. //        forceFactorySettings - Whether the option values should be set to
  96. //                             default values.
  97. //
  98. //  Return Value:
  99. //      None.
  100. //
  101. global proc normalConstraintSetup(string $parent, int $forceFactorySettings)
  102. {
  103.     //    Retrieve the option settings
  104.     //
  105.     setOptionVars($forceFactorySettings);
  106.  
  107.     setParent $parent;
  108.  
  109.     //    Query the optionVar's and set the values into the controls.
  110.  
  111.     //    weight
  112.     //
  113.     floatSliderGrp -edit 
  114.         -value `optionVar -query normalConstraintWeight`
  115.         normalConstraintWeight;
  116.  
  117.     //    aimVector.
  118.     //
  119.     float $aimVector[] = `optionVar -query normalConstraintAimVector`;
  120.     floatFieldGrp -edit 
  121.         -value1 $aimVector[0]
  122.         -value2 $aimVector[1]
  123.         -value3 $aimVector[2]
  124.         normalConstraintAimVector;
  125.  
  126.     //    upVector.
  127.     //
  128.     float $upVector[] = `optionVar -query normalConstraintUpVector`;
  129.     floatFieldGrp -edit 
  130.         -value1 $upVector[0]
  131.         -value2 $upVector[1]
  132.         -value3 $upVector[2]
  133.         normalConstraintUpVector;
  134.  
  135.     // World up
  136.  
  137.     string $worldUpType = `optionVar -query normalConstraintWorldUpType`;
  138.     switch ( $worldUpType )
  139.     {
  140.     case "scene":
  141.         optionMenuGrp -edit -select 1 normalConstraintWorldUpType;
  142.         break;
  143.     case "object":
  144.         optionMenuGrp -edit -select 2 normalConstraintWorldUpType;
  145.         break;
  146.     case "objectrotation":
  147.         optionMenuGrp -edit -select 3 normalConstraintWorldUpType;
  148.         break;
  149.     case "vector":
  150.         optionMenuGrp -edit -select 4 normalConstraintWorldUpType;
  151.         break;
  152.     case "none":
  153.         optionMenuGrp -edit -select 5 normalConstraintWorldUpType;
  154.         break;
  155.     }
  156.  
  157.     float $worldUpVector[] = `optionVar -query normalConstraintWorldUpVector`;
  158.     floatFieldGrp -edit 
  159.         -value1 $worldUpVector[0]
  160.         -value2 $worldUpVector[1]
  161.         -value3 $worldUpVector[2]
  162.         normalConstraintWorldUpVector;
  163.  
  164.     textFieldGrp -edit
  165.         -text `optionVar -query normalConstraintWorldUpObject`
  166.         normalConstraintWorldUpObject;
  167.  
  168.     normalConstraintEnabling $parent;
  169. }
  170.  
  171. //
  172. //  Procedure Name:
  173. //      normalConstraintCallback
  174. //
  175. //  Description:
  176. //        Update the option values with the current state of the option box UI.
  177. //
  178. //  Input Arguments:
  179. //      parent - Top level parent layout of the option box UI.  Required so
  180. //               that UI object names can be successfully resolved.
  181. //
  182. //        doIt   - Whether the command should execute.
  183. //
  184. //  Return Value:
  185. //      None.
  186. //
  187. global proc normalConstraintCallback(string $parent, int $doIt)
  188. {
  189.     setParent $parent;
  190.  
  191.     //    Set the optionVar's from the control values, and then
  192.     //    perform the command.
  193.  
  194.     //    weight
  195.     //
  196.     optionVar -floatValue normalConstraintWeight
  197.         `floatSliderGrp -query -value normalConstraintWeight`;
  198.  
  199.     //    aimVector.
  200.     //
  201.     optionVar -floatValue normalConstraintAimVector
  202.         `floatFieldGrp -query -value1 normalConstraintAimVector`
  203.         -floatValueAppend normalConstraintAimVector
  204.         `floatFieldGrp -query -value2 normalConstraintAimVector`
  205.         -floatValueAppend normalConstraintAimVector
  206.         `floatFieldGrp -query -value3 normalConstraintAimVector`;
  207.  
  208.     //    upVector.
  209.     //
  210.     optionVar -floatValue normalConstraintUpVector
  211.         `floatFieldGrp -query -value1 normalConstraintUpVector`
  212.         -floatValueAppend normalConstraintUpVector
  213.         `floatFieldGrp -query -value2 normalConstraintUpVector`
  214.         -floatValueAppend normalConstraintUpVector
  215.         `floatFieldGrp -query -value3 normalConstraintUpVector`;
  216.  
  217.     // World up
  218.  
  219.     int $state = `optionMenuGrp -query -select normalConstraintWorldUpType`;
  220.     switch ( $state )
  221.     {
  222.     case 1:
  223.         optionVar -stringValue normalConstraintWorldUpType "scene";
  224.         break;
  225.     case 2:
  226.         optionVar -stringValue normalConstraintWorldUpType "object";
  227.         break;
  228.     case 3:
  229.         optionVar -stringValue normalConstraintWorldUpType "objectrotation";
  230.         break;
  231.     case 4:
  232.         optionVar -stringValue normalConstraintWorldUpType "vector";
  233.         break;
  234.     case 5:
  235.         optionVar -stringValue normalConstraintWorldUpType "none";
  236.         break;
  237.     }
  238.  
  239.     optionVar -floatValue normalConstraintWorldUpVector
  240.         `floatFieldGrp -query -value1 normalConstraintWorldUpVector`
  241.         -floatValueAppend normalConstraintWorldUpVector
  242.         `floatFieldGrp -query -value2 normalConstraintWorldUpVector`
  243.         -floatValueAppend normalConstraintWorldUpVector
  244.         `floatFieldGrp -query -value3 normalConstraintWorldUpVector`;
  245.  
  246.     optionVar -stringValue normalConstraintWorldUpObject
  247.         `textFieldGrp -query -text normalConstraintWorldUpObject`;
  248.  
  249.     if ($doIt) {
  250.         performNormalConstraint 0; 
  251.         addToRecentCommandQueue "performNormalConstraint 0" "NormalConstraint";
  252.     }
  253. }
  254.  
  255. // Callbacks to dim/undim different widget
  256. //
  257. global proc normalConstraintEnabling(string $parent)
  258. {
  259.     setParent $parent;
  260.  
  261.     int $state = `optionMenuGrp -query -select normalConstraintWorldUpType`;
  262.     switch ( $state )
  263.     {
  264.     case 1: // Scene Up
  265.     case 5: // None
  266.         floatFieldGrp -edit -enable false normalConstraintWorldUpVector;
  267.         textFieldGrp -edit -enable false normalConstraintWorldUpObject;
  268.         break;
  269.     case 2: // Object Up
  270.         floatFieldGrp -edit -enable false normalConstraintWorldUpVector;
  271.         textFieldGrp -edit -enable true normalConstraintWorldUpObject;
  272.         break;
  273.     case 3: // Object Rotation Up
  274.         floatFieldGrp -edit -enable true normalConstraintWorldUpVector;
  275.         textFieldGrp -edit -enable true normalConstraintWorldUpObject;
  276.         break;
  277.     case 4: // Vector
  278.         floatFieldGrp -edit -enable true normalConstraintWorldUpVector;
  279.         textFieldGrp -edit -enable false normalConstraintWorldUpObject;
  280.         break;
  281.     }
  282. }
  283.  
  284. //
  285. //  Procedure Name:
  286. //      normalConstraintOptions
  287. //
  288. //  Description:
  289. //        Construct the option box UI.  Involves accessing the standard option
  290. //        box and customizing the UI accordingly.
  291. //
  292. //  Input Arguments:
  293. //      None.
  294. //
  295. //  Return Value:
  296. //      None.
  297. //
  298. proc normalConstraintOptions()
  299. {
  300.     //    Name of the command for this option box.
  301.     //
  302.     string $commandName = "normalConstraint";
  303.  
  304.     //    Build the option box actions.
  305.     //
  306.     string $callback = ($commandName + "Callback");
  307.     string $setup = ($commandName + "Setup");
  308.  
  309.     //    Get the option box.
  310.     //
  311.     string $layout = getOptionBox();
  312.     setParent $layout;
  313.     
  314.     //    Pass the command name to the option box.
  315.     //
  316.     setOptionBoxCommandName($commandName);
  317.     
  318.     //    Activate the default UI template.
  319.     //
  320.     setUITemplate -pushTemplate DefaultTemplate;
  321.  
  322.     //    Turn on the wait cursor.
  323.     //
  324.     waitCursor -state 1;
  325.  
  326.     string $parent = `columnLayout -adjustableColumn 1`;
  327.     
  328.     floatSliderGrp -label "Weight"
  329.         -field true -min 0.0 -max 10.0 
  330.         normalConstraintWeight;
  331.  
  332.     floatFieldGrp -label "Aim Vector"
  333.         -numberOfFields 3
  334.         normalConstraintAimVector;
  335.  
  336.     floatFieldGrp -label "Up Vector"
  337.         -numberOfFields 3
  338.         normalConstraintUpVector;
  339.  
  340.     optionMenuGrp -l "World Up Type"
  341.         -cc ("normalConstraintEnabling " + $parent)
  342.         normalConstraintWorldUpType;
  343.         menuItem -l "Scene Up"           normalConstraintUpDirMI1;
  344.         menuItem -l "Object Up"          normalConstraintUpDirMI2;
  345.         menuItem -l "Object Rotation Up" normalConstraintUpDirMI3;
  346.         menuItem -l "Vector"             normalConstraintUpDirMI4;
  347.         menuItem -l "None"               normalConstraintUpDirMI5;
  348.  
  349.     floatFieldGrp -l "World Up Vector" -nf 3 normalConstraintWorldUpVector;
  350.  
  351.     textFieldGrp -l "World Up Object" normalConstraintWorldUpObject;
  352.  
  353.     //    Turn off the wait cursor.
  354.     //
  355.     waitCursor -state 0;
  356.     
  357.     //    Deactivate the default UI template.
  358.     //
  359.     setUITemplate -popTemplate;
  360.  
  361.     //    'Apply' button.
  362.     //
  363.     string $applyBtn = getOptionBoxApplyBtn();
  364.     button -edit
  365.         -label "Add"
  366.         -command ($callback + " " + $parent + " " + 1)
  367.         $applyBtn;
  368.  
  369.     //    'Save' button.
  370.     //
  371.     string $saveBtn = getOptionBoxSaveBtn();
  372.     button -edit 
  373.         -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
  374.         $saveBtn;
  375.  
  376.     //    'Reset' button.
  377.     //
  378.     string $resetBtn = getOptionBoxResetBtn();
  379.     button -edit 
  380.         -command ($setup + " " + $parent + " " + 1)
  381.         $resetBtn;
  382.  
  383.     //    Set the option box title.
  384.     //
  385.     setOptionBoxTitle("Normal Constraint Options");
  386.  
  387.     //    Customize the 'Help' menu item text.
  388.     //
  389.     setOptionBoxHelpTag( "Normal" );
  390.  
  391.     //    Set the current values of the option box.
  392.     //
  393.     eval (($setup + " " + $parent + " " + 0));    
  394.     
  395.     //    Show the option box.
  396.     //
  397.     showOptionBox();
  398. }
  399.  
  400. //
  401. //  Procedure Name:
  402. //      normalConstraintHelp
  403. //
  404. //  Description:
  405. //        Return a short description about this command.
  406. //
  407. //  Input Arguments:
  408. //      None.
  409. //
  410. //  Return Value:
  411. //      string.
  412. //
  413. proc string normalConstraintHelp()
  414. {
  415.     // ******** Example
  416.     // "  Command: Extrude - create a surface using extrusion.\n" +
  417.     // "Selection: curves and isoparms."
  418.  
  419.     return 
  420.     "  Command: normalConstraint - Creates a normal constraint.n" +
  421.     "Selection: <A list of things that can be selected>";    
  422. }
  423.  
  424. //
  425. //  Procedure Name:
  426. //      assembleCmd
  427. //
  428. //  Description:
  429. //        Construct the command that will apply the option box values.
  430. //
  431. //  Input Arguments:
  432. //      None.
  433. //
  434. //  Return Value:
  435. //      None.
  436. //
  437. proc string assembleCmd()
  438. {
  439.     string $cmd = "normalConstraint";
  440.  
  441.     setOptionVars(false);
  442.  
  443.     float $aimVector[] = `optionVar -query normalConstraintAimVector`;
  444.     float $upVector[] = `optionVar -query normalConstraintUpVector`;
  445.  
  446.     $cmd = ($cmd 
  447.             + " -weight " + `optionVar -query normalConstraintWeight`
  448.             + " -aimVector " 
  449.             + $aimVector[0] + " " + $aimVector[1] + " " + $aimVector[2]
  450.             + " -upVector " 
  451.             + $upVector[0] + " " + $upVector[1] + " " + $upVector[2]
  452.         );
  453.     
  454.     // world up related options
  455.     
  456.     string $worldUpType = `optionVar -query normalConstraintWorldUpType`;
  457.     $cmd = ($cmd  + " -worldUpType " + "\"" + $worldUpType + "\"" );
  458.     switch ( $worldUpType )
  459.     {
  460.     case "scene":
  461.     case "none":
  462.         break;
  463.     case "object":
  464.         string $worldUpObject = `optionVar -query normalConstraintWorldUpObject`;
  465.         $cmd = ($cmd  + " -worldUpObject " + $worldUpObject);
  466.         break;
  467.     case "objectrotation":
  468.         float $worldUpVector[] = `optionVar -query normalConstraintWorldUpVector`;
  469.         $cmd = ($cmd  + " -worldUpVector " 
  470.                 + $worldUpVector[0] + " "
  471.                 + $worldUpVector[1] + " "
  472.                 + $worldUpVector[2]);
  473.         string $worldUpObject = `optionVar -query normalConstraintWorldUpObject`;
  474.         $cmd = ($cmd  + " -worldUpObject " + $worldUpObject);
  475.         break;
  476.     case "vector":
  477.         float $worldUpVector[] = `optionVar -query normalConstraintWorldUpVector`;
  478.         $cmd = ($cmd  + " -worldUpVector " 
  479.                 + $worldUpVector[0] + " "
  480.                 + $worldUpVector[1] + " "
  481.                 + $worldUpVector[2]);
  482.         break;
  483.     }
  484.  
  485.     return $cmd;
  486. }
  487.  
  488. //
  489. //  Procedure Name:
  490. //      performNormalConstraint
  491. //
  492. //  Description:
  493. //        Perform the normalConstraint command using the corresponding 
  494. //        option values.  This procedure will also show the option box
  495. //        window if necessary as well as construct the command string
  496. //        that will invoke the normalConstraint command with the current
  497. //        option box values.
  498. //
  499. //  Input Arguments:
  500. //      0 - Execute the command.
  501. //      1 - Show the option box dialog.
  502. //      2 - Return the command.
  503. //
  504. //  Return Value:
  505. //      None.
  506. //
  507. global proc string performNormalConstraint(int $action)
  508. {
  509.     string $cmd = "";
  510.  
  511.     switch ($action) {
  512.  
  513.         //    Execute the command.
  514.         //
  515.         case 0:
  516.             //    Retrieve the option settings
  517.             //
  518.             setOptionVars(false);
  519.  
  520.             //    Get the command.
  521.             //
  522.             $cmd = `assembleCmd`;
  523.  
  524.             //    Execute the command with the option settings.
  525.             //
  526.             evalEcho($cmd);
  527.  
  528.             break;
  529.  
  530.         //    Show the option box.
  531.         //
  532.         case 1:
  533.             normalConstraintOptions;
  534.             break;
  535.  
  536.         //    Return the command string.
  537.         //
  538.         case 2:
  539.             //    Retrieve the option settings.
  540.             //
  541.             setOptionVars (false);
  542.  
  543.             //    Get the command.
  544.             //
  545.             $cmd = `assembleCmd`;
  546.             break;
  547.     }
  548.     return $cmd;
  549. }
  550.  
  551.